package Proxy;

import java.lang.reflect.Proxy;

public class ProxyFactory {

    public static Object getProxyInstance(Object obj){
        MyInvocationHander handerler =new MyInvocationHander();
        handerler.bind(obj);
        return Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(),handerler);

    }

    public static void main(String[] args) {
        buyCar b = new buyCar();
        carFactory proxyInstance = (carFactory) ProxyFactory.getProxyInstance(b);
        proxyInstance.makeCar();
        buyCloth1 b1 = new buyCloth1();
        clothFactory proxyInstance1 = (clothFactory) getProxyInstance(b1);
        proxyInstance1.makeCloth();
        buyCar2 b2 = new buyCar2();
        carFactory proxyInstance2 = (carFactory) ProxyFactory.getProxyInstance(b2);
        proxyInstance2.makeCar();
    }
}
